package com.appkubes.mall.restful.application.common.basic.service;

import com.appkubes.mall.restful.application.common.basic.MapApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class BaiduMapService<T> implements MapApiService<T> {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${baidumap.ak}")
    private String ak;

    @Value("${baidumap.url}")
    private String url;

    public T getRealyAddress(Double latitude,Double longitude, Class<T> clazz){
        String reqUrl = url.replace("#(lat)", String.valueOf(latitude))
                            .replace("#(lng)", String.valueOf(longitude))
                            .replace("#(ak)", ak);
        T obj = restTemplate.getForObject(reqUrl, clazz);
        return obj;
    }
}
